import 'package:Flutter_Demo/core/viewmodel/fliter_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import "../../../core/extention/int_extention.dart";

class MYFliterContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        bulidHeader(context),
        buildContent(context),

      ],
    );
  }


  Widget bulidHeader(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(20.px),
      child: Text("展示你的选择", style: Theme.of(context).textTheme.headline3.copyWith(fontWeight: FontWeight.bold),),
    );
  }

  Widget buildContent(BuildContext context) {
    return Expanded(
      child: Consumer<MYFliterViewModel>(
        builder: (ctx, fliterViewModel, child) {
          return ListView(
            children: <Widget>[
              bulidContentItem("无谷蛋白", "无谷蛋白，无谷蛋白", fliterViewModel.isGlutenFree, (value){
                fliterViewModel.isGlutenFree = value;
              }),
              bulidContentItem("不含乳糖", "不含乳糖，不含乳糖", fliterViewModel.isLactoseFree, (value){
                fliterViewModel.isLactoseFree = value;
              }),
              bulidContentItem("素食主义", "素食主义，素食主义", fliterViewModel.isVegetarian, (value){
                fliterViewModel.isVegetarian = value;
              }),
              bulidContentItem("严格素食主义", "严格素食主义，严格素食主义", fliterViewModel.isVegan, (value){
                fliterViewModel.isVegan = value;
              })

            ],
          );
        },
      ),
    );
  }

  Widget bulidContentItem(String title, String subtitle, bool value, Function onChanged) {
    return ListTile(
      title: Text(title),
      subtitle: Text(subtitle),
      trailing: Switch(value: value, onChanged: onChanged),
    );
  }


}
